using namespace std;
#define UsefullEffi_cxx
#include "UsefullEffi.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>

#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>

void UsefullEffi::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L UsefullEffi.C
//      Root > UsefullEffi t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
   if (fChain == 0) return;

   map<string,pair<double,double> > cemap; 
   Long64_t nentries = fChain->GetEntriesFast();
   fstream file("effiall.txt");
   Int_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      if(cemap.find(CE.fData)==cemap.end()) {
        cemap[CE.fData]=pair<double,double>(0,0);
      } 
      // if (Cut(ientry) < 0) continue;
      if (type=="REGISTERED-DONE-RAN" || type=="REGISTERED-DONE-RAN-CLEARED" || type=="REGISTERED-DONE") {
       cemap[CE.fData].first=cemap[CE.fData].first+(logmonitor_wn_Time/3600);
      } else {
       cemap[CE.fData].second=cemap[CE.fData].second+(logmonitor_wn_Time/3600);
      }
   }
   for(map<string,pair<double,double> >::iterator i=cemap.begin(); i!=cemap.end(); i++) { 
      cout << (*i).first << " " << (*i).second.first << " " << (*i).second.second <<  endl; 
      file << (*i).first << " " << (*i).second.first << " " << (*i).second.second <<  endl; 
   }
}
